import {GetEnterpriseList,GetAlarmsList  } from "@/service/index.js";
import $store from '@/store/index.js'
import moment from 'moment'

//报警统计上部的弹框配置
export const topDialogConfig = {
    detailPropList:[//表格的列信息
        { prop: 'time', label: '报警时间', minWidth: '100',timeStampFormat:"YYYY-MM-DD HH:mm:ss" },
        { prop: 'enterprisename', label: '所属企业', minWidth: '100' },
        { prop: 'type', label: '报警类型', minWidth: '100' },
        { prop: 'pointname', label: '报警点位', minWidth: '100' },
        { prop: 'alarmlevel', label: '报警等级', minWidth: '100'},
        { prop: 'parkname', label: '所属园区', minWidth: '100'},
        { prop: 'districtname', label: '所属区县', minWidth: '100'},
    ],
    showSearch:true,//是否显示搜索区域
    searchConfig:{//搜索区域配置
        labelWidth: '100px',
        itemStyle: {
            padding: '10px'
        },
        colLayout: {
            span: 6
        },
        searchProps: [
            {
                field: 'enterpriseids',
                type: 'select',
                label: '所属企业',
                placeholder: '请输入所属企业',
                options: async()=>{
                    const res = await GetEnterpriseList({})
                    if(res.code==200){
                        let result = res.data?.map(item=>{
                            return {
                                title:item.entfullname,
                                value:item.entunifiedcode
                            }
                        })
                        return result??[]
                    }else{
                        return []
                    }
                },
                otherOptions: {
                    filterable:true
                }
            },
        ]
    },
    getTableDataFunction:(pagenum,pagesize,queryInfo)=>{//数据初始化方法
        let params = {...queryInfo,pageIndex:pagenum,pageSize:pagesize}//重新定义page，改成接口需要的
        return new Promise((resolve)=>{
            GetAlarmsList(params)
            .then(res=>{
                if (res.data && res.code == "200") {
                    const querysuccess = true;
                    const totalcount = res.total;
                    const datalist = res.data;
                    resolve({querysuccess,totalcount,datalist})
                }else{
                    const querysuccess = false;
                    const totalcount = 0;
                    const datalist = [];
                    resolve({querysuccess,totalcount,datalist})
                }
            })
        })
    }
}
//报警统计左边的弹框配置
export const middleLeftDialogConfig = {
    detailPropList:[//表格的列信息
        { prop: 'time', label: '报警时间', minWidth: '100',timeStampFormat:"YYYY-MM-DD HH:mm:ss" },
        { prop: 'enterprisename', label: '所属企业', minWidth: '100' },
        { prop: 'type', label: '报警类型', minWidth: '100' },
        { prop: 'pointname', label: '报警点位', minWidth: '100' },
        { prop: 'alarmlevel', label: '报警等级', minWidth: '100'},
        { prop: 'parkname', label: '所属园区', minWidth: '100'},
        { prop: 'districtname', label: '所属区县', minWidth: '100'},
    ],
    showSearch:true,//是否显示搜索区域
    searchConfig:{//搜索区域配置
        labelWidth: '100px',
        itemStyle: {
            padding: '10px'
        },
        colLayout: {
            span: 6
        },
        searchProps: [
            {
                field: 'type',
                type: 'select',
                label: '报警类型',
                placeholder: '请输入报警类型',
                options: ()=>{
                    return $store.state.sysParamsData.filter(item => item.setname == "报警类型").map(item=>{
                        return{
                            title:item.name,
                            value:item.code
                        }
                    })
                },
                otherOptions: {
                    filterable:true
                }
            },
        ]
    },
    getTableDataFunction:(pagenum,pagesize,queryInfo)=>{//数据初始化方法
        let params = {...queryInfo,pageIndex:pagenum,pageSize:pagesize}//重新定义page，改成接口需要的
        return new Promise((resolve)=>{
            GetAlarmsList(params)
            .then(res=>{
                if (res.data && res.code == "200") {
                    const querysuccess = true;
                    const totalcount = res.total;
                    const datalist = res.data;
                    resolve({querysuccess,totalcount,datalist})
                }else{
                    const querysuccess = false;
                    const totalcount = 0;
                    const datalist = [];
                    resolve({querysuccess,totalcount,datalist})
                }
            })
        })
    }
}
//报警统计中部的弹框配置
export const middleCenterDialogConfig = {
    detailPropList:[//表格的列信息
        { prop: 'time', label: '报警时间', minWidth: '100',timeStampFormat:"YYYY-MM-DD HH:mm:ss" },
        { prop: 'enterprisename', label: '所属企业', minWidth: '100' },
        { prop: 'type', label: '报警类型', minWidth: '100' },
        { prop: 'pointname', label: '报警点位', minWidth: '100' },
        { prop: 'alarmlevel', label: '报警等级', minWidth: '100'},
        { prop: 'parkname', label: '所属园区', minWidth: '100'},
        { prop: 'districtname', label: '所属区县', minWidth: '100'},
    ],
    showSearch:true,//是否显示搜索区域
    searchConfig:{//搜索区域配置
        labelWidth: '100px',
        itemStyle: {
            padding: '10px'
        },
        colLayout: {
            span: 6
        },
        searchProps: [
            {
                field: 'enterpriseids',
                type: 'select',
                label: '所属企业',
                placeholder: '请输入所属企业',
                options: async()=>{
                    const res = await GetEnterpriseList({})
                    if(res.code==200){
                        let result = res.data?.map(item=>{
                            return {
                                title:item.entfullname,
                                value:item.entunifiedcode
                            }
                        })
                        return result??[]
                    }else{
                        return []
                    }
                },
                otherOptions: {
                    filterable:true
                }
            },
        ]
    },
    getTableDataFunction:(pagenum,pagesize,queryInfo)=>{//数据初始化方法
        let params = {...queryInfo,pageIndex:pagenum,pageSize:pagesize}//重新定义page，改成接口需要的
        return new Promise((resolve)=>{
            GetAlarmsList(params)
            .then(res=>{
                if (res.data && res.code == "200") {
                    const querysuccess = true;
                    const totalcount = res.total;
                    const datalist = res.data;
                    resolve({querysuccess,totalcount,datalist})
                }else{
                    const querysuccess = false;
                    const totalcount = 0;
                    const datalist = [];
                    resolve({querysuccess,totalcount,datalist})
                }
            })
        })
    }
}
//报警统计右侧的弹框配置
export const middleRightDialogConfig = {
    detailPropList:[//表格的列信息
        { prop: 'time', label: '报警时间', minWidth: '100',timeStampFormat:"YYYY-MM-DD HH:mm:ss" },
        { prop: 'enterprisename', label: '所属企业', minWidth: '100' },
        { prop: 'type', label: '报警类型', minWidth: '100' },
        { prop: 'pointname', label: '报警点位', minWidth: '100' },
        { prop: 'alarmlevel', label: '报警等级', minWidth: '100'},
        { prop: 'parkname', label: '所属园区', minWidth: '100'},
        { prop: 'districtname', label: '所属区县', minWidth: '100'},
    ],
    showSearch:true,//是否显示搜索区域
    searchConfig:{//搜索区域配置
        labelWidth: '100px',
        itemStyle: {
            padding: '10px'
        },
        colLayout: {
            span: 6
        },
        searchProps: [
            {
                field: 'alarmlevel',
                type: 'select',
                label: '报警级别',
                placeholder: '请输入报警级别',
                options: [
                    {title:"紧急",value:"紧急"},
                    {title:"重要",value:"重要"},
                    {title:"一般",value:"一般"},
                ],
                otherOptions: {
                    filterable:true
                }
            },
            {
                field: 'alarmtime',
                type: 'datepicker',
                label: '时间',
                otherOptions: {
                    placeholder:"选择月份",
                    type: 'month',
                    format:"YYYY-MM",
                    valueFormat:"YYYY-MM"
                }
            }
        ]
    },
    getTableDataFunction:(pagenum,pagesize,queryInfo)=>{//数据初始化方法
        let params = {...queryInfo,pageIndex:pagenum,pageSize:pagesize}//重新定义page，改成接口需要的

        let month = params.alarmtime;
        let start = month+"-01 00:00:00"
        let endtime = moment(start).endOf('month').format("YYYY-MM-DD HH:mm:ss")

        params.begintime = start
        params.endtime = endtime
        
        return new Promise((resolve)=>{
            GetAlarmsList(params)
            .then(res=>{
                if (res.data && res.code == "200") {
                    const querysuccess = true;
                    const totalcount = res.total;
                    const datalist = res.data;
                    resolve({querysuccess,totalcount,datalist})
                }else{
                    const querysuccess = false;
                    const totalcount = 0;
                    const datalist = [];
                    resolve({querysuccess,totalcount,datalist})
                }
            })
        })
    }
}
//报警统计底部的弹框配置
export const bottomDialogConfig = {
    detailPropList:[//表格的列信息
        { prop: 'time', label: '报警时间', minWidth: '100',timeStampFormat:"YYYY-MM-DD HH:mm:ss" },
        { prop: 'enterprisename', label: '所属企业', minWidth: '100' },
        { prop: 'type', label: '报警类型', minWidth: '100' },
        { prop: 'pointname', label: '报警点位', minWidth: '100' },
        { prop: 'alarmlevel', label: '报警等级', minWidth: '100'},
        { prop: 'parkname', label: '所属园区', minWidth: '100'},
        { prop: 'districtname', label: '所属区县', minWidth: '100'},
    ],
    showSearch:true,//是否显示搜索区域
    searchConfig:{//搜索区域配置
        labelWidth: '100px',
        itemStyle: {
            padding: '10px'
        },
        colLayout: {
            span: 6
        },
        searchProps: [
            {
                field: 'alarmtime',
                type: 'datepicker',
                label: '时间',
                otherOptions: {
                    placeholder:"选择月份",
                    type: 'month',
                    format:"YYYY-MM",
                    valueFormat:"YYYY-MM"
                }
            }
        ]
    },
    getTableDataFunction:(pagenum,pagesize,queryInfo)=>{//数据初始化方法
        let params = {...queryInfo,pageIndex:pagenum,pageSize:pagesize}//重新定义page，改成接口需要的
        let month = params.alarmtime;
        let start = month+"-01 00:00:00"
        let endtime = moment(start).endOf('month').format("YYYY-MM-DD HH:mm:ss")
        params.begintime = start
        params.endtime = endtime
        return new Promise((resolve)=>{
            GetAlarmsList(params)
            .then(res=>{
                if (res.data && res.code == "200") {
                    const querysuccess = true;
                    const totalcount = res.total;
                    const datalist = res.data;
                    resolve({querysuccess,totalcount,datalist})
                }else{
                    const querysuccess = false;
                    const totalcount = 0;
                    const datalist = [];
                    resolve({querysuccess,totalcount,datalist})
                }
            })
        })
    }
}